;Assembles best with NASM or FASM
;Do not use MASM
org 0x1000	; (comment out this line for yasm compatibility)
use16	; (comment out this line for yasm compatibility)

mov word [SECTORS_PER_TRACK],ax
mov word [NUMBER_OF_DRIVES],bx
mov word [NUMBER_OF_HEADS],cx
mov [DRIVE_TYPE],dh
mov [drive],dl

;cli				; clear interrupts
;	xor	ax, ax			; null segments
;	mov	ds, ax
;	mov	es, ax
;	mov	ax, 0x9000		; stack begins at 0x9000-0xffff
;	mov	ss, ax
;	mov	sp, 0xFFFF
;	sti

mov ax,0x0003
int 10h

mov ah,33
int 0x33
mov ah,1
int 0x33

start:
call clear_screen
call newlin_e
mov di,found
mov al,'v'
stosb
mov al,'l'
stosb
mov al,'h'
stosb
call command
call newlin_e
mov si,drive_f
call prnstr
mov al,[drive]
cmp al,0x00
je d_imsgf
cmp al,0x80
je d_imsgh
mov si,imsgf
call prnstr
jmp d_imsg_e
d_imsgf:
mov si,imsgf
call prnstr
jmp d_imsg_e
d_imsgh:
mov si,imsgh
call prnstr
jmp d_imsg_e
d_imsg_e:
mov byte al,[drive]
call printh

call reg_int

kernel:

call newlin

command_line:
call chkkey
jz command_line
cmp ah,0x48
je previous_comm
cmp ah,0x0f
je page_change_key
jmp command_start

previous_comm:
mov si,found
call prnstr
mov di,si
jmp command_set

page_change_key:
jmp page_change

command_start:
mov di,found
command_set:
call getarg

mov byte al,[found]
cmp al,0
je kernel

call newlin_e

mov si,found
mov di,c_load
call cmpstr
jc load_link

mov si,found
mov di,c_save
call cmpstr
jc save_link

mov si,found
mov di,c_text
call cmpstr
jc text_link

mov si,found
mov di,c_code
call cmpstr
jc text_link

mov si,found
mov di,c_print
call cmpstr
jc text_link

mov si,found
mov di,c_clock
call cmpstr
jc clock_link

jmp extracomms

load_link:
jmp load_f

save_link:
jmp save_f

text_link:
jmp text

clock_link:
jmp clock

extracomms:

mov si,found
mov di,c_run
call cmpstr
jc run_link

mov si,found
mov di,c_drive
call cmpstr
jc c_drive_f_link

mov si,found
mov di,c_drive2
call cmpstr
jc c_drive2_f_link

mov si,found
mov di,c_loc
call cmpstr
jc c_loc_f_link

mov si,found
mov di,c_loc2
call cmpstr
jc c_loc2_f_link

mov si,found
mov di,c_loc3
call cmpstr
jc c_loc3_f_link

mov si,found
mov di,c_htod
call cmpstr
jc c_htod_f_link

jmp extracomm2

run_link:
jmp run

c_drive_f_link:
jmp c_drive_f

c_drive2_f_link:
jmp c_drive2_f

c_loc_f_link:
jmp c_loc_f

c_loc2_f_link:
jmp c_loc2_f

c_loc3_f_link:
jmp c_loc3_f

c_htod_f_link:
jmp c_htod_f

extracomm2:

mov si,found
mov di,c_reset
call cmpstr
jc c_reset_f_link

mov si,found
mov di,c_cls
call cmpstr
jc c_cls_f_link

mov si,found
mov di,c_prompt
call cmpstr
jc c_prompt_f_link

mov si,found
mov di,c_color
call cmpstr
jc c_color_f_link

mov si,found
mov di,c_typemode
call cmpstr
jc c_typemode_f_link

mov si,found
mov di,c_videomode
call cmpstr
jc c_videomode_f_link

jmp extracomm3

c_reset_f_link:
jmp c_reset_f

c_cls_f_link:
jmp c_cls_f

c_prompt_f_link:
jmp c_prompt_f

c_color_f_link:
jmp c_color_f

c_typemode_f_link:
jmp c_typemode_f

c_videomode_f_link:
jmp c_videomode_f

extracomm3:

mov si,found
mov di,c_memsize
call cmpstr
jc c_memsize_f_link

mov si,found
mov di,c_reboot
call cmpstr
jc c_reboot_f_link

mov si,found
mov di,c_restart
call cmpstr
jc c_restart_f_link

mov si,found
mov di,c_page
call cmpstr
jc c_page_f_link

mov si,found
mov di,c_star
call cmpstr
jc c_mousemode_f_link

mov si,found
mov di,c_sound
call cmpstr
jc c_sound_f_link

mov si,found
mov di,c_cli
call cmpstr
jc c_cli_f_link

mov si,found
mov di,c_hlt
call cmpstr
jc c_hlt_f_link

mov si,found
mov di,c_fhlt
call cmpstr
jc c_fhlt_f_link

mov si,found
mov di,c_jmp
call cmpstr
jc c_jmp_f_link

mov si,found
mov di,c_paint
call cmpstr
jc c_paint_f_link

mov si,found
mov di,c_score
call cmpstr
jc c_score_f_link

mov si,found
mov di,c_play
call cmpstr
jc c_play_f_link

mov si,found
mov di,c_calc
call cmpstr
jc c_calc_f_link

jmp extracomms4

c_memsize_f_link:
jmp c_memsize_f

c_reboot_f_link:
jmp c_reboot_f

c_restart_f_link:
jmp c_restart_f

c_page_f_link:
jmp c_page_f

c_mousemode_f_link:
jmp c_mousemode_f

c_sound_f_link:
jmp c_sound_f

c_cli_f_link:
jmp c_cli_f

c_hlt_f_link:
jmp c_hlt_f

c_fhlt_f_link:
jmp c_fhlt_f

c_jmp_f_link:
jmp c_jmp_f

c_paint_f_link:
jmp c_paint_f

c_score_f_link:
jmp c_score_f

c_play_f_link:
jmp c_play_f

c_calc_f_link:
jmp c_calc_f

extracomms4:

mov si,found
mov di,c_size
call cmpstr
jc c_size_f_link

mov si,found
mov di,c_scrollmode
call cmpstr
jc c_scrollmode_f_link

mov si,found
mov di,c_slowmode
call cmpstr
jc c_slowmode_f_link

mov si,found
mov di,c_debuginfo
call cmpstr
jc c_debuginfo_f_link

mov si,found
mov di,c_settime
call cmpstr
jc c_settime_f_link

mov si,found
mov di,c_setdate
call cmpstr
jc c_setdate_f_link

mov si,found
mov di,c_install
call cmpstr
jc c_install_f_link

mov si,found
mov di,c_head
call cmpstr
jc c_head_f_link

mov si,found
mov di,c_track
call cmpstr
jc c_track_f_link

mov si,found
mov di,c_point
call cmpstr
jc c_point_f_link

mov si,found
mov di,c_icon
call cmpstr
jc c_icon_f_link

mov si,found
mov di,c_length
call cmpstr
jc c_length_f_link

mov si,found
mov di,c_scrolllen
call cmpstr
jc c_scrolllen_f_link

jmp extracomm5

c_size_f_link:
jmp c_size_f

c_scrollmode_f_link:
jmp c_scrollmode_f

c_slowmode_f_link:
jmp c_slowmode_f

c_debuginfo_f_link:
jmp c_debuginfo_f

c_settime_f_link:
jmp c_settime_f

c_setdate_f_link:
jmp c_setdate_f

c_install_f_link:
jmp c_install_f

c_head_f_link:
jmp c_head_f

c_track_f_link:
jmp c_track_f

c_point_f_link:
jmp c_point_f

c_icon_f_link:
jmp c_icon_f

c_length_f_link:
jmp c_length_f

c_scrolllen_f_link:
jmp c_scrolllen_f

extracomm5:

mov si,found
mov di,c_difficulty
call cmpstr
jc c_difficulty_f_link

mov si,found
mov di,c_doc
call cmpstr
jc c_doc_f_link

mov si,found
mov di,c_fname
call cmpstr
jc fname_link

mov si,found
mov di,c_alarm
call cmpstr
jc alarm_link

mov si,found
mov di,c_alarmtext
call cmpstr
jc alarmtext_link

mov si,found
mov di,c_autostart
call cmpstr
jc autostart_link

mov si,found
mov di,c_setting
call cmpstr
jc setting_link

mov byte bl,[found]
cmp bl,'z'
je fdir_link
cmp bl,'a'
je fdir_link
cmp bl,'q'
je fdir_link

;mov byte bl,[found]
cmp bl,'x'
je filesave_link

mov byte bl,[found]
cmp bl,'n'
je filenew_link

jmp command_link

c_difficulty_f_link:
jmp c_difficulty_f

c_doc_f_link:
jmp doc

fname_link:
jmp fname

alarm_link:
jmp alarm

alarmtext_link:
jmp alarmtext

setting_link:
jmp c_setting_f

autostart_link:
jmp c_autostart_f

filesave_link:
jmp filesave

filenew_link:
jmp filenew

fdir_link:
jmp fdir

command_link:

mov bx,comm
mov al,[found]
mov [bx],al
call command

progend:
jmp kernel

load_f:
xor bh,bh
call getno
mov ah,0x02
jmp drive_comm

save_f:
xor bh,bh
call getno
mov ah,0x03
jmp drive_comm

run:
mov word bx,[loc]
sub bx,0x0500
call bx
jmp kernel

move_right:
pusha
call getpos
inc dl
call setpos
popa
inc cx
jmp text_control

move_down:
pusha
call getpos
inc dh
call setpos
popa
add cx,80
jmp text_control

text:
mov cx,0x0000
mov si,[loc]
text_loop:
lodsb
inc cx
cmp byte [found],'c'
je code_show
cmp byte [found],'p'
je print_file
call printf
jmp text_loop_check
code_show:
call printh
jmp text_loop_check
print_file:
xor ah,ah
xor dx,dx
int 17h
text_loop_check:
cmp cx,0x200
jge text_shown
jmp text_loop
text_shown:
cmp byte [found],'c'
je code_control
cmp byte [found],'p'
je kernel
text_control:
mov ah,0x00
int 16h
cmp ah,0x01
je kernel
cmp ah,0x29
je kernel
cmp ah,0x48
je move_up
cmp ah,0x4B
je move_left
cmp ah,0x4D
je move_right
cmp ah,0x50
je move_down

mov bx,[loc]
add bx,cx
mov [bx],al
pusha
call printf
popa
inc cx
jmp text_control

move_up:
pusha
call getpos
dec dh
call setpos
popa
sub cx,80
jmp text_control

move_left:
pusha
call getpos
dec dl
call setpos
popa
dec cx
jmp text_control

code_control:
call chkkey

jz code_control
cmp ah,0x01
je kernel
cmp ah,0x29
je kernel
cmp ah,0x48
je code_move_up
cmp ah,0x4B
je code_move_left
cmp ah,0x4D
je code_move_right
cmp ah,0x50
je code_move_down

call gethex
mov bx,[loc]
add bx,cx
mov [bx],al
inc cx
jmp code_control

code_move_up:
call getkey
pusha
call getpos
dec dh
call setpos
popa
sub cx,40
jmp code_control

code_move_left:
call getkey
pusha
call getpos
sub dl,2
call setpos
popa
dec cx
jmp code_control

code_move_right:
call getkey
pusha
call getpos
add dl,2
call setpos
popa
inc cx
jmp code_control

code_move_down:
call getkey
pusha
call getpos
inc dh
call setpos
popa
add cx,40
jmp code_control

c_drive_f:
mov si,drive
call change
jmp kernel

c_drive2_f:
mov si,drive2
call change
jmp kernel

c_loc_f:
;mov si,loc
mov bx,loc
inc bx
call gethex
mov byte [bx],al
dec bx
call gethex
mov byte [bx],al
;call change
jmp kernel

c_loc2_f:
;mov si,loc
mov bx,loc2
inc bx
call gethex
mov byte [bx],al
dec bx
call gethex
mov byte [bx],al
;call change
jmp kernel

c_loc3_f:
;mov si,loc
mov bx,loc3
inc bx
call gethex
mov byte [bx],al
dec bx
call gethex
mov byte [bx],al
;call change
jmp kernel

c_reset_f:
mov ah,0x00
mov al,[mode]
int 10h
jmp kernel

c_reset_c:
mov ah,0x00
mov al,[mode]
int 10h
ret

c_cls_f:
call clear_screen
xor dx,dx
call setpos
jmp kernel

c_prompt_f:
mov di,prompt
call getstr
jmp kernel

c_color_f:
mov si,color
call change
jmp kernel

c_typemode_f:
not byte [teletype]
jmp kernel

c_videomode_f:
mov si,mode
call change
xor ah,ah
int 10h
jmp kernel

c_memsize_f:
int 12h
mov word [comm],ax
mov bh,ah
call printn
mov word ax,[comm]
mov bh,al
call printn
call colon
mov ah,0x88
int 15h
mov word [comm],ax
mov bh,ah
call printn
mov word ax,[comm]
mov bh,al
call printn
jmp kernel

printf_c:
pusha
mov bh,[page]
mov ah,0x09
mov bl,[color]
mov cx,0x0001
int 0x10
popa
ret

printf_b:
pusha
call printf_c
call getpos
inc dl
call setpos_c
popa
ret

printf:

cmp byte [teletype],0xf0
je printt

pusha
mov bh,[page]
mov ah,0x09
mov bl,[color]
mov cx,0x0001
int 0x10
call update_pos
popa
ret

printt:
pusha
mov ah,0x0e
mov bh,[color]
mov bl,[page]
int 10h
popa
ret

getpos:
mov ah,0x03
mov bh,[page]
int 10h
ret

setpos_c:
mov ah,0x02
mov bh,[page]
int 10h
ret

setpos:
cmp dl,0
jl update_pos_c_z
cmp dh,0
jl update_pos_r_z
cmp dh,24
jg update_pos_r
cmp dl,79
jg update_pos_c
jmp update_pos_e
update_pos_r_z:
xor dh,dh
jmp setpos
update_pos_c_z:
mov dl,79
dec dh
jmp setpos
update_pos_c:
inc dh
xor dl,dl
jmp setpos
update_pos_r:
cmp byte [scrollmode],0x0f
je update_scroll_off
call scroll_down
mov dh,25
sub dh,[scrolllength]
jmp setpos
update_scroll_off:
call clear_screen
xor dh,dh
jmp setpos
update_pos_e:
mov ah,0x02
mov bh,[page]

int 10h
ret

clear_screen:
pusha
mov ax,0x0600
call clear_bios_function
popa
ret

clear_bios_function:
mov ch,0x00
mov cl,0x00
mov dl,79
mov dh,24
mov bh,[color]
cmp byte [teletype],0xf0
je clear_screen_tele
rol bh,4
clear_screen_tele:
int 10h
ret

scroll_down:
pusha
mov ah,0x06
mov al,[scrolllength]
call clear_bios_function
popa
ret

update_pos:
call getpos
inc dl
call setpos
ret

printn:
mov al,'A'
push ax
reverse:
mov al,bh
mov bl,10
mov ah,0
div bl
mov bh,al
mov al,ah
add al,48
push ax
cmp bh,0
jg reverse
printne:
pop ax
cmp al,'A'
jne printnf
jmp printnq
printnf:
call printf
jmp printne
printnq:
ret

printh:
mov [comm],al
shr al,4
cmp al,10
sbb al,69h
das
call printf
mov al,[comm]
ror al,4
shr al,4
cmp al,10
sbb al,69h
das
call printf
ret

printwordh:
push ax
mov al,ah
call printh
pop ax
call printh
ret

printdwordh:
push ax
mov ax,dx
call printwordh
pop ax
call printwordh
ret

gethex:
call getkey
call printf
call atohex
shl al,4
mov [comm],al

call getkey
call printf
call atohex
mov ah,[comm]
add al,ah
ret

atohex:
cmp al,0x3a
jle hex_num_found
cmp al,0x5a
jg hex_small_found
add al,0x20
hex_small_found:
sbb al,0x28
hex_num_found:
sbb al,0x2f
ret

prnstr:
lodsb
or al,al
jz prnend
call printf
loop prnstr
prnend:
ret

chkkey:
mov ah,0x11
int 0x16
ret

getkey:
call chkkey
jz getkey
mov ah,0x10
int 0x16
ret

getno2:
pusha
getno_loop:
call getkey
call printf
cmp al,0x0D
je getno2e
sub al,0x30
mov cl,al
mov ax,bx
mov dx,0x000a
mul dx
mov bx,ax
xor ch,ch
add bx,cx
;xor ah,ah
;add word bx,ax
jmp getno_loop
getno2e:
popa
ret

getno:
call getkey
call printf
cmp al,0x0D
je getnoe
sub al,48
push ax
mov al,bh
mov bl,10
mul bl
mov bh,al
pop ax
add bh,al
jmp getno
getnoe:
ret

getstr:
call getkey
call printf
cmp al,0x0d
je strf
cmp ah,0x01
je strf
cmp ah,0x0e
je strb
stosb
jmp getstr
strb:
dec di
call eraseback
call eraseback
jmp getstr
strf:
mov ax,0x0000
stosb
ret

getarg:
call getkey
call printf
cmp al,0x20
je argf
cmp al,0x0d
je argf
cmp ah,0x01
je arge
cmp ah,0x0e
je argb
stosb
jmp getarg
argb:
dec di
call eraseback
call eraseback
jmp getarg
argf:
mov ax,0x0000
stosb
ret
arge:
mov byte [found],0x00
ret

eraseback:
call getpos
dec dl
call setpos
mov al,0x20
call printf_c
ret

cmpstr:
mov al,[si]
mov bl,[di]
cmp al,bl
jne nequal
cmp al,dh
je cmpend
cmp al,0
je cmpend
inc di
inc si
jmp cmpstr
nequal:
clc
ret
cmpend:
stc
ret

newlin:
call getpos
xor dl,dl
inc dh
call setpos
mov si,prompt
call prnstr
ret

newlin_e:
call getpos
xor dl,dl
inc dh
call setpos
ret

drive_comm:
pusha
mov cl,bh
mov bx,ds
mov es,bx
mov byte al,[size]
mov ch,[track]
mov dh,[head]
mov byte dl,[drive]
mov word bx,[loc]
int 13h
popa
jmp kernel

timer:
mov ah,0x00
int 0x1a
mov bh,ch
call printn
call colon
mov bh,cl
call printn
call colon
mov bh,dh
call printn
call colon
mov bh,dl
call printn
ret

date:
mov ah,0x04
int 0x1a
mov al,dl
call printh
call colon
mov al,dh
call printh
call colon
mov al,ch
call printh
;call colon
mov al,cl
call printh
ret

command:
mov bx,found
mov al,'d'
cmp [bx],al
je c_date_f_link
mov al,'t'
cmp [bx],al
je c_time_f
mov al,'c'
cmp [bx],al
je c_timer_f_link
mov al,'h'
cmp [bx],al
je c_help_f_link
mov al,'v'
cmp [bx],al
je c_ver_f
;mov al,'i'
;cmp [bx],al
;je c_install_f_link
mov al,'m'
cmp [bx],al
je c_mousemode_c_link
mov al,'s'
cmp [bx],al
je c_space_f_link
mov al,'p'
cmp [bx],al
je c_pause_f_link
mov al,'u'
cmp [bx],al
je c_up_f_link
mov al,'b'
cmp [bx],al
je c_below_f_link
mov al,'o'
cmp [bx],al
je c_oh_f_link
mov al,'l'
cmp [bx],al
je c_line_f_link
mov al,'e'
cmp [bx],al
je c_exit_f
ret

c_date_f_link:
jmp c_date_f

c_timer_f_link:
jmp c_timer_f

c_pause_f_link:
jmp c_pause_f

c_up_f_link:
jmp c_up_f

c_below_f_link:
jmp c_below_f

c_oh_f_link:
jmp c_oh_f

c_line_f_link:
jmp c_line_f

c_space_f_link:
jmp c_space_f

c_help_f_link:
jmp c_help_f

;c_install_f_link:
;jmp c_install_f

c_mousemode_c_link:
jmp c_mousemode_f

c_ver_f:
mov si,verstring
call prnstr
mov si,found
call strshift
jmp command

c_time_f:
call printf
call colon
call time
mov si,found
call strshift
jmp command

c_date_f:
call printf
call colon
call date
mov si,found
call strshift
jmp command

c_timer_f:
call printf
call colon
call timer
mov si,found
call strshift
jmp command

c_exit_f:
call printf
xor bx,bx
mov cx,0x0102
mov ax,0x530e
int 0x15
mov cx,0x0003
mov bx,0x0001
mov ax,0x5307
int 0x15

xor bx,bx
mov ax,0x5301
int 0x15
xor bx,bx
mov cx,0x0102
mov ax,0x530e
int 0x15
mov cx,0x0003
mov bx,0x0001
mov ax,0x5307
int 0x15
mov si,found
call strshift
jmp command

c_pause_f:
call getkey
mov si,found
call strshift
jmp command

c_up_f:
mov ax,0x0602
call clear_bios_function
call getpos
sub dh,4
call setpos
mov si,found
call strshift
jmp command

c_below_f:
mov ax,0x0702
call clear_bios_function
mov si,found
call strshift
jmp command

c_oh_f:
call getpos
sub dh,4
call setpos
mov si,found
call strshift
jmp command

c_line_f:
call newlin_e
mov si,found
call strshift
jmp command

c_space_f:
call space
mov si,found
call strshift
jmp command

c_help_f:
mov si,command_list
call prnstr
call newlin_e
mov si,extra_command_list
call prnstr
call newlin_e
mov si,more_command_list
call prnstr
call newlin_e
mov si,assembly_code
call prnstr
call newlin_e
mov si,common_control
call prnstr
call newlin_e
mov si,extra_command
call prnstr
call newlin_e
mov si,extra_command2
call prnstr
call newlin_e
mov si,file_command
call prnstr
call newlin_e
mov si,interrupt_api
call prnstr
call newlin_e
mov si,time_list
call prnstr
call newlin_e
mov si,mint_list
call prnstr
call newlin_e
mov si,mint2_list
call prnstr
mov si,found
call strshift
jmp command

c_install_f:

mov ax,ds
mov es,ax

mov ax,0x0201
mov bx,[loc]
mov cx,0x0001
mov dh,0x00
mov byte dl,[drive]
int 0x13
jnc c_install_hwri
jmp c_installend_f
c_install_hwri:
mov si,imsgh
call prnstr
c_install_wri:
xor ax,ax
mov es,ax
mov cx,0x0001
mov dh,00h
mov byte dl,[drive2]
mov bx,[loc]
mov ax,0x0301
int 13h
jc c_installend_f
;xor ax,ax
;mov es,ax
;mov cx,0x0002
;mov dh,00h
;mov byte dl,[drive2]
;mov bx,1000h
;mov ax,0x030d
;int 13h
;jc c_installend_f
mov si,imsgs
call prnstr
jmp c_installsuccess_f
c_installend_f:
mov si,imsge
call prnstr
c_installsuccess_f:
;mov si,found
;call strshift
;jmp command
jmp kernel

time:
mov ah,0x02
int 0x1a
mov al,ch
call printh
call colon
mov al,cl
call printh
call colon
mov al,dh
call printh
ret

c_cli_f:
cli
jmp kernel

c_hlt_f:
hlt
jmp kernel

c_fhlt_f:
mov si,shutdownstr
call prnstr
.loop:
cli
hlt
jmp .loop

c_jmp_f:
mov word bx,[loc]
sub bx,0x0050
jmp bx
jmp kernel

c_reboot_f:
mov byte dl,[drive]
int 19h
jmp kernel

c_restart_f:
in al,0x64
cmp al,0x02
je c_restart_f
mov al,0xfe
out 0x64,al
jmp kernel

c_page_f:
mov si,page
call change
mov byte al,[page]
mov ah,0x05
int 10h
jmp kernel

c_sound_f:
call PlayWAV
mov ax,0x80
mov al,[size]
int 0x1a
;mov cx,0xffff
;sound_loop:
;dec cx
;mov al,0x1
;out 0x61,al
;cmp cx,0x0000
;je sound_loop
jmp kernel

c_mousemode_f:
mov ax,0x0013
int 10h
JMP MAINP

PS2SET:
  mov  al, 0xa8
  out  0x64, al
  call CHKPRT
ret


CHKPRT:
  xor  cx, cx		
 .again:
  in   al, 0x64
  test al, 2
  jz  .chkprtgo
  jmp .again
.chkprtgo:
ret


WMOUS:
  mov  al, 0xd4
  out  0x64, al
  call CHKPRT
ret


MBUFFUL:
  xor  cx, cx
 .mn:
  in   al, 0x64
  test al, 0x20
  jz  .mnn
  loop .mn
 .mnn:
ret



ACTMOUS:
  call WMOUS
  mov  al, 0xf4
  out  0x60, al
  call CHKPRT
  call CHKMOUS
ret

CHKMOUS:
  mov  bl, 0
  xor  cx, cx
 .vrd:
  in   al, 0x64	
  test al, 1
  jnz .yy
  loop .vrd
  mov  bl, 1
 .yy:
ret


DKEYB:
  mov  al, 0xad
  out  0x64, al
  call CHKPRT
ret


EKEYB:
  mov  al, 0xae
  out  0x64, al
  call CHKPRT
ret

GETB:
 .cagain:
  call CHKMOUS
or bl,bl
jz GETB_exit
cmp byte [found],'s'
je mouse_action_star
jmp .cagain
GETB_exit:
  call DKEYB
  xor  ax, ax
  in   al, 0x60
  mov  dl, al
  call EKEYB
  mov  al, dl
ret
mouse_action_star:
call mousedrawstar
jmp GETB

GETFIRST:
  call GETB
  xor  ah, ah
  mov  bl, al
  and  bl, 1
  mov  BYTE [LBUTTON], bl
  mov  bl, al
  and  bl, 2
  shr  bl, 1
  mov  BYTE [RBUTTON], bl
  mov  bl, al
  and  bl, 4
  shr  bl, 2
  mov  BYTE [MBUTTON], bl
  mov  bl, al
  and  bl, 16
  shr  bl, 4
  mov  BYTE [XCOORDN], bl
  mov  bl, al
  and  bl, 32
  shr  bl, 5
  mov  BYTE [YCOORDN], bl
  mov  bl, al
  and  bl, 64
  shr  bl, 6
  mov  BYTE [XFLOW], bl
  mov  bl, al
  and  bl, 128
  shr  bl, 7
  mov  BYTE [YFLOW], bl
ret



GETSECOND:
  call GETB
  xor  ah, ah
  mov  BYTE [XCOORD], al
ret


GETTHIRD:
  call GETB
  xor  ah, ah
  mov  BYTE [YCOORD], al
ret



MAINP:
  call PS2SET
  call ACTMOUS
  call GETB	
mouse_main:
  call GETFIRST
  call GETSECOND
  call GETTHIRD

 mov BYTE [row], 10
 mov BYTE [col], 0

cmp byte [found],'s'
je no_disp_select
jmp mouse_disp
no_disp_select:
jmp no_mouse_disp
mouse_disp:
 call GOTOXY
call newlin
mov al,'X'
call printf
mov byte bh,[xmouse]
call printn
call space
mov al,'Y'
call printf
mov byte bh,[ymouse]
call printn
call newlin_e
 mov  si, strcdx
 call prnstr
 mov  al, BYTE [XCOORDN]
 or   al, al
 jz  .negative
 mov  si, strneg
 call prnstr
 jmp .positive
.negative:
 mov  si, strsp
 call prnstr
.positive:
 xor  ah, ah
 mov  al, BYTE [XCOORD]
 call DISPDEC
 call newlin_e

 mov  si, strcdy	; display the text for Ycoord
 call prnstr
 mov  al, BYTE [YCOORDN]
 or   al, al
 jz  .negativex
 mov  si, strneg	; if the sign bit is 1 then display - sign
 call prnstr
 jmp .positivex
.negativex:
 mov  si, strsp 	; else display a space
 call prnstr
.positivex:
 xor  ah, ah
 mov  al, BYTE [YCOORD]
 call DISPDEC
 call newlin_e


 mov  si, strlbt	; display the text for Lbutton
 call prnstr
 mov  al, BYTE [LBUTTON]
 xor  ah, ah
 call DISPDEC
  call newlin_e


 mov  si, strrbt	; display the text for Rbutton
 call prnstr
 mov  al, BYTE [RBUTTON]
 xor  ah, ah
 call DISPDEC
 call newlin_e
 

 mov  si, strmbt	; display the text for Mbutton
 call prnstr
 mov  al, BYTE [MBUTTON]
 xor  ah, ah
 call DISPDEC
 call newlin_e
no_mouse_disp:
call update_mouse

    xor  ax, ax
    mov  ah, 0x11
    int  0x16
    jnz quitprog

jmp mouse_main

quitprog:

mov bx,comm
mov byte [bx],'0'
call c_reset_c
jmp command

update_mouse:

mov byte al,[XCOORD]
mov word bx,[xmouse]

cmp al,0x7f
jg update_x_pos
add bx,ax
jmp update_x_pos_done
update_x_pos:
sub bx,ax
update_x_pos_done:
mov word [xmouse],bx

mov byte al,[YCOORD]
mov word bx,[ymouse]

cmp al,0x7f
jg update_y_pos
sub bx,ax
jmp update_y_pos_done
update_y_pos:
add bx,ax
update_y_pos_done:
mov word [ymouse],bx
xor bx,bx
mov word [XCOORD],bx
mov word [YCOORD],bx
mov word [XCOORDN],bx
mov word [YCOORDN],bx
ret
mousedrawstar:
mov bh,[page]
mov word cx,[xmouse]
mov word dx,[ymouse]
mov al,cl
mov ah,0x0c
int 10h
ret

DISPDEC:
    mov  BYTE [zerow], 0x00
    mov  WORD [varbuff], ax
    xor  ax, ax
    xor  cx, cx
    xor  dx, dx
    mov  bx, 10000
    mov  WORD [deel], bx
   .mainl:
    mov  bx, WORD [deel]
    mov  ax, WORD [varbuff]
    xor  dx, dx
    xor  cx, cx
    div  bx
    mov  WORD [varbuff], dx
    jmp .ydisp
   
   .vdisp:
    cmp  BYTE [zerow], 0x00
    je .nodisp

   .ydisp:
    mov  ah, 0x0E			    
    add  al, 48 			     
    mov  bx, 1 
    int  0x10				    
    mov  BYTE [zerow], 0x01
   jmp .yydis

   .nodisp:

   .yydis:
    xor  dx, dx
    xor  cx, cx
    xor  bx, bx
    mov  ax, WORD [deel]
    cmp  ax, 1
    je .bver
    cmp  ax, 0
    je .bver
    mov  bx, 10
    div  bx
    mov  WORD [deel], ax
   jmp .mainl

   .bver:
   ret

GOTOXY:
    mov dl, BYTE [col]
    mov dh, BYTE [row]
call setpos
ret

c_scrollmode_f:
not byte [scrollmode]
jmp kernel

c_slowmode_f:
not byte [slowmode]
jmp kernel

c_size_f:
mov si,size
call change
jmp kernel

c_debuginfo_f:
push es
mov ah, 8
int 13h                       ; get drive parameters
mov [DRIVE_TYPE], bl
and cx, 3Fh                   ; maximum sector number
mov [SECTORS_PER_TRACK], cx
mov [NUMBER_OF_DRIVES], dl
movzx dx, dh                  ; maximum head number
add dx, 1
mov [NUMBER_OF_HEADS], dx
pop es

mov si,drive_f
call prnstr
mov al,[drive]
cmp al,0x00
je di_imsgf
cmp al,0x80
je di_imsgh
mov si,imsgo
call prnstr
jmp di_imsg_e
di_imsgf:
mov si,imsgf
call prnstr
jmp di_imsg_e
di_imsgh:
mov si,imsgh
call prnstr
;jmp di_imsg_e
di_imsg_e:
mov al,[drive]
call printh
call colon
mov bh,[drive]
call printn
call newlin_e

mov si,drive_type_string
call prnstr
mov al,[DRIVE_TYPE]
call printh
call newlin_e
mov si,drive_number_string
call prnstr
mov al,[NUMBER_OF_DRIVES]
call printh
call newlin_e
mov si,drive_spt_string
call prnstr
mov al,[SECTORS_PER_TRACK]
call printwordh
call newlin_e
mov si,drive_head_string
call prnstr
mov al,[NUMBER_OF_HEADS]
call printwordh

jmp kernel

change:
xor bx,bx
call getno
mov [si],bh
ret

drawdot:
mov ah,0x0c
int 10h
ret

c_paint_f:
mov ax,0x0013
int 10h

mov si,[loc]
mov cx,0x0000
mov dx,0x0000
image_loop:
lodsb
push ax
mov al,ah
call drawdot
pop ax
call drawdot
inc cx
cmp cx,320
jne image_loop
mov cx,0x0000
inc dx
cmp dx,200
jne image_loop
mov word [player_x],20
mov word [player_y],20
mov word [player2_x],20
mov word [player2_y],20
mov word [comm],0x1914
mov word [varbuff],0x1914
paint_draw:
mov ch,0x00
mov dh,0x00
mov cl,[player_x]
mov dl,[player_y]
mov bh,[page]
mov al,[color]
call drawdot
mov cl,[player2_x]
mov dl,[player2_y]
mov bh,[page]
mov al,[color2]
call drawdot

call getkey
paint_control:
cmp ah,0x4b
je paint_key_left
cmp ah,0x4d
je paint_key_right
cmp ah,0x48
je paint_key_up
cmp ah,0x50
je paint_key_down
jmp paint2_control

paint_key_left:
mov cx,[player_x]
mov dx,[player_y]
dec cx
dec word [comm]
jmp paint_key_done
paint_key_right:
mov cx,[player_x]
mov dx,[player_y]
inc cx
inc word [comm]
jmp paint_key_done
paint_key_up:
mov cx,[player_x]
mov dx,[player_y]
dec dx
sub word [comm],0x0140
jmp paint_key_done
paint_key_down:
mov cx,[player_x]
mov dx,[player_y]
inc dx
add word [comm],0x0140
jmp paint_key_done

paint_key_done:
mov [player_x],cx
mov [player_y],dx
mov bx,[loc]
add bx,[comm]
mov al,[color]
mov byte [bx],al
jmp paint_draw

paint2_control:
cmp ah,0x11
je paint_key_w
cmp ah,0x1e
je paint_key_a
cmp ah,0x1f
je paint_key_s
cmp ah,0x20
je paint_key_d
jmp other_key

paint_key_a:
mov cx,[player2_x]
mov dx,[player2_y]
dec cx
dec word [varbuff]
jmp paint2_key_done
paint_key_d:
mov cx,[player2_x]
mov dx,[player2_y]
inc cx
inc word [varbuff]
jmp paint2_key_done
paint_key_w:
mov cx,[player2_x]
mov dx,[player2_y]
dec dx
sub word [varbuff],0x0140
jmp paint2_key_done
paint_key_s:
mov cx,[player2_x]
mov dx,[player2_y]
inc dx
add word [varbuff],0x0140
jmp paint2_key_done

paint2_key_done:
mov [player2_x],cx
mov [player2_y],dx
mov bx,[loc]
add bx,[varbuff]
mov al,[color2]
mov byte [bx],al
jmp paint_draw

other_key:
cmp ah,0x01
je paint_exit
cmp ah,0x29
je paint_exit
mov byte [color],ah
mov byte [color2],al
jmp paint_draw

paint_exit:
jmp kernel

c_play_f:
mov byte [player_y],0x0c
mov byte [player_x],0x00
mov byte [player2_y],0x0c
mov byte [player2_x],0x4f
mov byte [ball_y],0x0c
mov byte [ball_x],0x0c
mov byte [down_flag],0xf0
mov byte [right_flag],0xf0
mov byte [AI_flag],0xf0
mov word [deel],0x0000
mov word [extra],0x0000
mov byte al,[color]
mov byte [color2],al
mov ax,0x0003
int 10h
play_loop:
call play2_draw
call play_draw
cmp byte [score],0xf0
jne score_off
call score_draw
score_off:
call ball_draw
xor dx,dx
call setpos_c
cmp byte [slowmode],0xf0
je play_slowmode_on
call delay
jmp play_delay_done
play_slowmode_on:
call slow
play_delay_done:
mov byte [color],0x00
call ball_draw
call play2_draw
call play_draw
mov byte al,[color2]
mov byte [color],al
call ball_update
call setpos_c
cmp byte [AI_flag],0xF0
je AI_play_loop
jmp AI_player_chance
AI_play_loop:
mov byte al,[play_chance_flag]

cmp byte al,[difficulty]
jle AI_on
;jg AI_player_chance

AI_player_chance:
xor al,al
mov byte [play_chance_flag],al
call chkkey
jz play_loop

call getkey
cmp ah,0x01
je kernel
cmp ah,0x29
je kernel
cmp ah,0x12
je play_clear
cmp ah,0x48
je player1_up
cmp ah,0x50
je player1_down
cmp ah,0x0f
je switch_AI

cmp byte [AI_flag],0xF0
je AI_on

cmp ah,0x11
je player2_up
cmp ah,0x1f
je player2_down
jmp play_loop

AI_on:
jmp AI_play

switch_AI:
not byte [AI_flag]
jmp play_loop

player1_up:
mov dh,[player_y]
dec dh
mov [player_y],dh
jmp play_loop
player1_down:
mov dh,[player_y]
inc dh
mov [player_y],dh
jmp  play_loop
player2_up:
mov dh,[player2_y]
dec dh
mov [player2_y],dh
jmp play_loop
player2_down:
mov dh,[player2_y]
inc dh
mov [player2_y],dh
jmp  play_loop
play_clear:
call c_reset_c
jmp play_loop

AI_play:
inc al
mov byte [play_chance_flag],al
mov dh,[player2_y]
inc dh
cmp byte [ball_y],dh
jg AI_ball_ahead
jl AI_ball_behind
jmp AI_exit
AI_ball_ahead:
inc dh
jmp AI_exit
AI_ball_behind:
dec dh
jmp AI_exit

AI_exit:
dec dh
mov byte [player2_y],dh
jmp play_loop

play_draw:
mov cl,[length]
mov dl,[player_x]
mov dh,[player_y]
play_draw_loop:
call setpos_c
mov al,0xdb
call printf_c
dec cl
inc dh
cmp dh,0x19
jg play_loop_extra
cmp dh,0x01
jl play_loop_less
cmp cl,0x00
jg play_draw_loop
jmp play_loop_exit
play_loop_extra:
mov dh,0x19
sub dh,[length]
mov [player_y],dh
jmp play_loop
play_loop_less:
mov dh,0x00
mov [player_y],dh
jmp play_loop
play_loop_exit:
ret

play2_draw:
mov cl,[length]
mov dl,[player2_x]
mov dh,[player2_y]
play2_draw_loop:
call setpos_c
mov al,0xdb
call printf_c
dec cl
inc dh
cmp dh,0x19
jg play2_loop_extra
cmp dh,0x01
jl play2_loop_less
cmp cl,0x00
jg play2_draw_loop
jmp play2_loop_exit
play2_loop_extra:
mov dh,0x19
sub dh,[length]
mov [player2_y],dh
jmp play_loop
play2_loop_less:
mov dh,0x00
mov [player2_y],dh
jmp play_loop
play2_loop_exit:
ret

ball_draw:
mov dl,[ball_x]
mov dh,[ball_y]
inc dl
call setpos_c
mov al,0xdb
call printf_b
call printf_b
mov dl,[ball_x]
mov dh,[ball_y]
inc dh
call setpos_c
mov al,0xdb
call printf_b
call printf_b
call printf_b
call printf_b

mov dl,[ball_x]
mov dh,[ball_y]
add dh,2
call setpos_c
mov al,0xdb
call printf_b
call printf_b
call printf_b
call printf_b

mov dl,[ball_x]
mov dh,[ball_y]
add dh,3
inc dl
call setpos_c
mov al,0xdb
call printf_b
call printf_b
ret

ball_update:
mov dl,[ball_x]
mov dh,[ball_y]

cmp byte [down_flag],0xf0
jne ball_going_up
inc dh
jmp vertical_update_done
ball_going_up:
dec dh
vertical_update_done:

cmp byte [right_flag],0xf0
jne ball_going_left
inc dl
jmp horizontal_update_done
ball_going_left:
dec dl
horizontal_update_done:

cmp dl,0x4b
jg right_wall
cmp dl,0x01
jl left_wall
cmp dh,0x15
jg bottom_wall
cmp dh,0x01
jl top_wall

jmp bounds_done
left_wall:
mov byte ah,[player_y]
call play_check_collision
jnc left_wall_fine
inc word [extra]
left_wall_fine:
not byte [right_flag]
jmp bounds_done
right_wall:
mov byte ah,[player2_y]
call play_check_collision
jnc right_wall_fine
inc word [deel]
right_wall_fine:
not byte [right_flag]
jmp bounds_done
bottom_wall:
mov dh,0x15
not byte [down_flag]
jmp bounds_done
top_wall:
mov dh,0x00
not byte [down_flag]
;jmp bounds_done
bounds_done:
mov byte [ball_x],dl
mov byte [ball_y],dh
ret

score_draw:
mov dx,0x1722
call setpos
mov word ax,[deel]
call printwordh
call colon
mov word ax,[extra]
call printwordh
ret

play_check_collision:
mov byte [XFLOW],dh
add dh,3
cmp dh,ah
jge coll_end_fine
jmp coll_detected
coll_end_fine:
sub dh,2
add byte ah,[length]
cmp dh,ah
jle coll_start_fine
jmp coll_detected
coll_start_fine:
mov byte dh,[XFLOW]
clc
ret
coll_detected:
mov byte dh,[XFLOW]
stc
ret

c_calc_f:
mov al,0x31
call printf
call colon
mov si,player_x
call change
call newlin_e
mov al,0x32
call printf
call colon
mov si,player_y
call change
call newlin_e
mov si,calc_options
call prnstr
call newlin_e
xor bh,bh
call getno
push bx
call newlin_e
pop bx
mov al,[player_x]
mov cl,[player_y]
cmp bh,1
je calc_add
cmp bh,2
je calc_sub
cmp bh,3
je calc_mul
cmp bh,4
je calc_div
cmp bh,5
je calc_dtoh
calc_add:
add al,cl
jmp calc_exit
calc_sub:
sub al,cl
jmp calc_exit
calc_mul:
mul cl
jmp calc_exit
calc_div:
div cl
jmp calc_exit
calc_dtoh:
call printh
call colon
calc_exit:
push ax
mov bh,ah
call printn
call colon
pop ax
mov bh,al
call printn
jmp kernel

delay:
xor ah,ah
int 1ah
mov byte [comm],dl
delay_loop:
xor ah,ah
int 1ah
cmp byte [comm],dl
je delay_loop
ret

slow:
mov ah,0x02
int 1ah
mov al,dh
mov byte [comm],al
slow_loop:
mov ah,0x02
int 0x1a
cmp byte dh,[comm]
je slow_loop
ret

colon:
mov al,':'
call printf
ret

space:
mov al,' '
call printf
ret

c_head_f:
mov si,head
call change
jmp kernel

c_track_f:
mov si,track
call change
jmp kernel

strshift:
inc si
mov al,[si]
dec si
mov [si],al
inc si
cmp al,0
jne strshift
ret

c_point_f:
mov ax,0x0013
int 10h
mov word [comm],0
mov si,[loc]
point_loop:
lodsb
mov byte [player_x],al
lodsb
mov byte [player_y],al
inc word [comm]
xor ch,ch
xor dh,dh
mov cx,[player_x]
mov dx,[player_y]
mov byte al,[color]
call drawdot
cmp word [comm],512
jl point_loop
jmp kernel

c_icon_f:
mov ax,0x0013
int 10h
mov si,[loc]
mov cx,100
mov dx,50
icon_loop:
lodsb
call drawdot
inc cx
cmp cx,132
jl icon_loop
mov cx,100
inc dx
cmp dx,66
jl icon_loop
jmp kernel

c_settime_f:
mov al,'H'
call printf
call colon
mov si,player_x
call change
call newlin_e
mov al,'M'
call printf
call colon
mov si,player_y
call change
call newlin_e
mov al,'S'
call printf
call colon
mov si,player2_x
call change

mov byte ch,[player_x]
mov byte cl,[player_y]
mov byte dh,[player2_x]
xor dl,dl
mov ah,0x03
int 0x1a
jmp kernel

c_setdate_f:
mov al,'C'
call printf
call colon
mov si,player_x
call change
call newlin_e
mov al,'Y'
call printf
call colon
mov si,player_y
call change
call newlin_e
mov al,'M'
call printf
call colon
mov si,player2_x
call change
call newlin_e
mov al,'D'
call printf
call colon
mov si,player2_y
call change

mov byte ch,[player_x]
mov byte cl,[player_y]
mov byte dh,[player2_x]
mov byte dl,[player2_y]
mov ah,0x05
int 0x1a
jmp kernel

;************************************************;
; Convert CHS to LBA
; LBA = (cluster - 2) * sectors per cluster
;************************************************;

ClusterLBA:
          sub     ax, 0x0002                          ; zero base cluster number
          xor     cx, cx
          mov     cl, BYTE [bpbSectorsPerCluster]     ; convert byte to word
          mul     cx
          add     ax, WORD [datasector]               ; base data sector
          ret

;************************************************;
; Convert LBA to CHS
; AX=>LBA Address to convert
;
; absolute sector = (logical sector / sectors per track) + 1
; absolute head   = (logical sector / sectors per track) MOD number of heads
; absolute track  = logical sector / (sectors per track * number of heads)
;
;************************************************;

LBACHS:
          xor     dx, dx                              ; prepare dx:ax for operation
          div     WORD [bpbSectorsPerTrack]           ; calculate
          inc     dl                                  ; adjust for sector 0
          mov     BYTE [absoluteSector], dl
          xor     dx, dx                              ; prepare dx:ax for operation
          div     WORD [bpbHeadsPerCylinder]          ; calculate
          mov     BYTE [absoluteHead], dl
          mov     BYTE [absoluteTrack], al
          ret


;************************************************;
; Reads a series of sectors
; CX=>Number of sectors to read
; AX=>Starting sector
; ES:BX=>Buffer to read to
;************************************************;

ReadSectors:
     Read_Sectors_MAIN:
          mov     di, 0x0005                          ; five retries for error
     Read_Sectors_SECTORLOOP:
          push    ax
          push    bx
          push    cx
          call    LBACHS                              ; convert starting sector to CHS
          mov     ah, 0x02                            ; BIOS read sector
          mov     al, [size]                            ; read one sector
          mov     ch, BYTE [absoluteTrack]            ; track
          mov     cl, BYTE [absoluteSector]           ; sector
          mov     dh, BYTE [absoluteHead]             ; head
          ;mov     dl, BYTE [bsDriveNumber]            ; drive
mov byte dl,[drive]
          int     0x13                                ; invoke BIOS
          jmp     Read_Sectors_SUCCESS                ; test for read error
          xor     ax, ax                              ; BIOS reset disk
          int     0x13                                ; invoke BIOS
          dec     di                                  ; decrement error counter
          pop     cx
          pop     bx
          pop     ax
          jnz     Read_Sectors_SECTORLOOP             ; attempt to read again
          int     0x18
     Read_Sectors_SUCCESS:
          mov     al, '.'
          call    printf
          pop     cx
          pop     bx
          pop     ax
          add     bx, WORD [bpbBytesPerSector]        ; queue next buffer
          inc     ax                                  ; queue next sector
          loop    Read_Sectors_MAIN                   ; read next sector
          ret
		  
fname:
mov di,ImageName
call getstr
call checkfname
jmp kernel

checkfname:
mov cx,0x000B
mov si,ImageName
.loop:
lodsb

cmp al,0x60
jg .small
cmp al,0x2E
je .dot
dec cx
;loop .loop
cmp cx,0x0000
jg .loop
ret
.small:
;inc cx
sub al,0x20
dec si
mov [si],al
;inc si
jmp .loop
.dot:
mov di,si
dec di
push di
mov cx,0x0003
call memcpy

pop si
mov di,ImageName
add di,0x0008
push si
mov cx,0x0003
call memcpy

mov si,ImageName
add si,0x0008
pop di
mov al,0x20
.dotloop:

stosb
cmp di,si
jl .dotloop
jmp checkfname

fdir:
cmp byte [found],'i'
jne .fdir_not_interrupt
;mov di,ImageName
;mov bx,di
mov ax,[loc]
mov [deel],ax
mov [loc],di
.fdir_not_interrupt:
call LOAD_ROOT
jmp fileload
jmp kernel

calculate_root:
; compute size of root directory and store in "cx"
     
          xor     cx, cx
          xor     dx, dx
          mov     ax, 0x0020                           ; 32 byte directory entry
          mul     WORD [bpbRootEntries]                ; total size of directory
          div     WORD [bpbBytesPerSector]             ; sectors used by directory
          xchg    ax, cx
          
     ; compute location of root directory and store in "ax"
     
          mov     al, BYTE [bpbNumberOfFATs]            ; number of FATs
          mul     WORD [bpbSectorsPerFAT]               ; sectors used by FATs
          add     ax, WORD [bpbReservedSectors]         ; adjust for bootsector
          mov     WORD [datasector], ax                 ; base of root directory
          add     WORD [datasector], cx
ret
		  
LOAD_ROOT:


     call calculate_root
          
     ; read root directory into memory (7C00:0200)
     
          mov word bx,[loc]                            ; copy root dir above bootcode
          call    ReadSectors
ret

     ;----------------------------------------------------
     ; Find stage 2
     ;----------------------------------------------------
fileload:
     ; browse root directory for binary image
          mov     cx, WORD [bpbRootEntries]             ; load loop counter
          mov word di, [loc]                            ; locate first root entry
     .LOOP:
          ;push    cx
          
          mov     si, ImageName                         ; image name to find
		  mov byte al,[di]
		  cmp al,0x00
		  je FAILURE
          push    di
		  ;push cx
		  cmp byte [found],'i'
je .intnonameload
call newlin_e
;pop cx
mov     cx, 0x000B                            ; eleven character name
mov si,di
call prnstr
.intnonameload:
mov si,ImageName
mov     cx, 0x000B                            ; eleven character name
repe  cmpsb	 ; test for entry match
pop di
je LOAD_FAT
;je DONE
cmp byte [found],'q'
je .quickload
cmp byte [found],'i'
je .intload
call getkey
cmp al,0x0D
je LOAD_FAT
cmp al,0x20
je LOAD_FAT
cmp ah,0x01
je FAILURE
.quickload:
.intload:
          ;pop     cx
          add     di, 0x0020                            ; queue next directory entry
          loop    .LOOP
		  jmp     FAILURE

     ;----------------------------------------------------
     ; Load FAT
     ;----------------------------------------------------

     LOAD_FAT:
     
     ; save starting cluster of boot image
     
          mov     dx, WORD [di + 0x001A]
          mov     WORD [cluster], dx                  ; file's first cluster
          
     call calculate_fat
          
     ; read FAT into memory (7C00:0200)

          mov word bx,[loc2]                          ; copy FAT above bootcode
          call ReadSectors
		  
     ; read image file into memory (0050:0000)
     
          ;mov word ax,0x0050
		  ;xor ax,ax
          ;mov     es, ax                              ; destination for image
          mov word bx,[loc]                          ; destination for image
          push    bx

     ;----------------------------------------------------
     ; Load Stage 2
     ;----------------------------------------------------

     LOAD_IMAGE:
     
          mov     ax, WORD [cluster]                  ; cluster to read
          pop     bx                                  ; buffer to read into
          call    ClusterLBA                          ; convert cluster to LBA
          xor     cx, cx
          mov     cl, BYTE [bpbSectorsPerCluster]     ; sectors to read
          call    ReadSectors
          push    bx
          call calculate_next_cluster
     
     DONE:
;push    WORD 0x0050
;push    WORD 0x0000
;retf
cmp byte [found],'i'
je intloaddone
mov al,'S'
call printf
call newlin_e
mov al,'H'
call printf
mov al,'='
call printf
mov byte al,[absoluteHead]
call printh
call colon
mov al,'T'
call printf
mov al,'='
call printf
mov byte al,[absoluteTrack]
call printh
call colon
mov al,'S'
call printf
mov al,'='
call printf
mov byte al,[absoluteSector]
call printh
jmp kernel

FAILURE:
cmp byte [found],'i'
je intloaddone
mov si, imsge
call prnstr
jmp kernel

intloaddone:
mov ax,[deel]
mov [loc],ax
iret
;mov ax,[varbuff]
;jmp ax

calculate_next_cluster:
; compute next cluster
     
          mov     ax, WORD [cluster]                  ; identify current cluster
          mov     cx, ax                              ; copy current cluster
          mov     dx, ax                              ; copy current cluster
          shr     dx, 0x0001                          ; divide by two
          add     cx, dx                              ; sum for (3/2)
          mov word bx, [loc2]                          ; location of FAT in memory
          add     bx, cx                              ; index into FAT
          mov     dx, WORD [bx]                       ; read two bytes from FAT
          test    ax, 0x0001
          jnz     .ODD_CLUSTER
          
     .EVEN_CLUSTER:
     
          and     dx, 0000111111111111b               ; take low twelve bits
         jmp     .DONE
         
     .ODD_CLUSTER:
     
          shr     dx, 0x0004                          ; take high twelve bits
          
     .DONE:
     
          cmp byte [found],'a'
		  jne complete_load_off
		  mov     WORD [cluster], dx                  ; store new cluster
          cmp     dx, 0x0FF0                          ; test for end of file
          jb      LOAD_IMAGE
		  complete_load_off:
ret

set_next_cluster:
          mov     ax, WORD [cluster]
          mov     cx, ax                              ; copy current cluster
          mov     dx, ax                              ; copy current cluster
          shr     dx, 0x0001                          ; divide by two
          add     cx, dx                              ; sum for (3/2)
          mov word bx, [loc2]                          ; location of FAT in memory
          add     bx, cx                              ; index into FAT
          mov     dx, WORD [bx]                       ; read two bytes from FAT
          test    ax, 0x0001
          jnz     .ODD_CLUSTER
          
     .EVEN_CLUSTER:
     
          and     dx, 0000111111111111b               ; take low twelve bits
         jmp     .DONE
         
     .ODD_CLUSTER:
     
          shr     dx, 0x0004                          ; take high twelve bits
          
     .DONE:
     mov dx,0xFFFF
          ;mov     WORD [cluster], dx                  ; store new cluster
mov word [bx],dx
;cmp     dx, 0x0FF0
;jb      LOAD_IMAGE
ret

calculate_fat:
; compute size of FAT and store in "cx"
     
          xor     ax, ax
          mov     al, BYTE [bpbNumberOfFATs]          ; number of FATs
          mul     WORD [bpbSectorsPerFAT]             ; sectors used by FATs
          mov     cx, ax

     ; compute location of FAT and store in "ax"

          mov     ax, WORD [bpbReservedSectors]       ; adjust for bootsector
		  ret

save_c:
pusha
mov dx,ds
mov es,dx
mov byte ah,0x03
mov byte ch,0x00
;mov byte cl,[sector]
;mov byte al,[size]
mov byte dh,0x00
mov byte dl,[drive]
;mov word bx,[loc]
int 13h
popa
ret

filesave:
pusha
mov bx,ds
mov es,bx
mov byte ah,0x03
mov byte al,[size]
mov byte ch,[absoluteTrack]
mov byte cl,[absoluteSector]
mov byte dh,[absoluteHead]
mov byte dl,[drive]
mov word bx,[loc]
int 13h
popa
jmp kernel

filenew:
mov al,[size]
mov [zerow],al
mov byte [size],0x01
call LOAD_ROOT
mov cx, WORD [bpbRootEntries]
mov word di,[loc]
call newlin_e

.loop:
mov si,di
call prnstr
call newlin_e
call getkey
cmp ah,0x1c
je filenew_found
mov al,[di]
cmp byte al,0x00
je filenew_found
add di,0x0020
jmp .loop
filenew_found:
sub di,0x0006
mov word ax,[di]
inc word ax
mov word [comm],ax
mov word [cluster],ax
add di,0x0006
;push di
mov si,ImageName
mov cx,0x000b
call memcpy
;pop di
mov al,0x20
stosb
mov al,0x18
stosb
mov al,0x1a
stosb
mov al,0x9a
stosb
mov al,0x42
stosb
mov al,0x7c
stosb
mov al,0x43
stosb
mov al,0x7c
stosb
mov al,0x43
stosb
mov al,0x00
stosb
stosb
mov al,0xca
stosb
mov al,0x93
stosb
mov al,0x76
stosb
mov al,0x43
stosb

;add di,0x000e
mov bx,comm
mov al,[bx]
stosb
inc bx
mov al,[bx]
stosb
inc di
mov al,0x02
stosb

call calculate_root
inc ax
xchg ax,cx
mov word bx,[loc]
call save_c

call calculate_fat
;inc ax
;xchg ax,cx
mov word bx,[loc2]
call ReadSectors
call set_next_cluster
call calculate_fat

;call printwordh
inc ax
xchg ax,cx
;call colon
;call printwordh

mov word bx,[loc2]
call save_c
mov al,[zerow]
mov [size],al
jmp kernel

memcpy:
lodsb
stosb
dec cx
cmp cx,0x0000
jg memcpy
ret

reload_words:
cmp cx,0x0000
jle reload_words_end
dec cx
mov byte al,[bx]
call printf
inc bx
jmp reload_words
reload_words_end:
ret

doc_up:
call getpos
dec dh
sub word [deel],0x50
call setpos
jmp doc_shown_control

doc_right:
call getpos
inc dl
inc word [deel]
call setpos
jmp doc_shown_control

doc:
mov ax,0x0200
mov byte cl,[size]
xor ch,ch
mul cx
mov word [varbuff],ax
mov word [deel],0x0000
mov si,[loc]
doc_loop:
lodsb
inc word [deel]
call printf
mov word cx,[deel]
cmp word cx,[varbuff]
jge doc_shown_control
cmp word [deel],0x07Cf
jge doc_shown
jmp doc_loop
doc_shown:
mov word [deel],0x004f
mov dx,0x0100
call setpos
doc_shown_control:
call getpos
cmp dh,0x00
jle doc_top_move
cmp dh,0x18
jge doc_bottom_move
jmp doc_control_fine

doc_top_move:
mov byte [player_x],dl
mov byte [player_y],dh
mov dx,0x0000
call setpos
;sub word [deel],0x0050
mov ax,0x0701
call clear_bios_function
mov word bx,[loc]
add word bx,[deel]
sub byte bl,[player_x]
mov cx,0x0050
call reload_words
mov byte dl,[player_x]
mov byte dh,[player_y]
inc dh
call setpos
jmp doc_control_fine

doc_bottom_move:
mov byte [player_x],dl
mov byte [player_y],dh
mov dx,0x1800
call setpos
;add word [deel],0x0050
mov ax,0x0601
call clear_bios_function
mov word bx,[loc]
sub byte bl,[player_x]
;add word bx,0x07D0
add word bx,[deel]
mov cx,0x004f
call reload_words
mov al,[bx]
call printf_c
mov byte dl,[player_x]
mov byte dh,[player_y]
dec dh
call setpos
jmp doc_control_fine

doc_control_fine:
call getkey
cmp ah,0x48
je doc_up
cmp ah,0x4b
je doc_left
cmp ah,0x4d
je doc_right
cmp ah,0x50
je doc_down
cmp ah,0x01
je doc_exit
cmp ah,0x29
je doc_exit
call printf
inc word [deel]
mov word bx,[loc]
add word bx,[deel]
mov byte [bx],al
jmp doc_shown_control
doc_exit:
call newprompt
jmp kernel

doc_left:
call getpos
dec dl
dec word [deel]
call setpos
jmp doc_shown_control

doc_down:
call getpos
inc dh
add word [deel],0x50
call setpos
jmp doc_shown_control

c_length_f:
mov si,length
call change
jmp kernel

c_htod_f:
call gethex
mov bh,al
call colon
call printn
jmp kernel

c_scrolllen_f:
mov si,scrolllength
call change
jmp kernel

c_score_f:
not byte [score]
jmp kernel

c_autostart_f:
not byte [autostart]
jmp kernel

clock:
mov al,'c'
call printf
call colon
call timer
call space
call newlin_e
mov al,'t'
call printf
call colon
call time
call space
call newlin_e
mov al,'d'
call printf
call colon
call date
call space
call getpos
call chkkey
jnz kernel
sub dh,2
xor dl,dl
call setpos
jmp clock

page_change:
call getkey
mov al,[page]
inc al
cmp al,0x07
jle page_fine
xor al,al
page_fine:
mov byte [page],al
mov ah,0x05
int 10h
call newprompt
jmp command_line

reg_int:
call set_timer
mov ax,0x0021
mov di,int21h
call set_ivt
mov ax,0x004A
mov di,int4ah
call set_ivt
;mov ax,0x0008
;mov di,int08h
;call set_ivt
;mov ax,0x0009
;mov di,int09h
;call set_ivt
ret

set_ivt:
xor dx,dx
mov es,dx
mov bl,0x04
mul bl
mov bx,ax
xor ax,ax
mov es,ax
mov word [bx],di
add bx,2
mov word [bx],0x0000
ret

ackport:
cmp al,0x0f
jle irqsmall
mov al,0x20
out 0xa0,al
irqsmall:
mov al,0x20
out 0x20,al
ret

clrport64:
jmp clrport64_loop
in al,0x60
clrport64_loop:
in al,0x64
and al,1
cmp al,0x01
jge clrport64
ret

int21h:
xor dx,dx
mov ds,dx
mov es,dx

cmp ah,0x4C
je int21h_close_process
cmp ah,0x3D
je int21h_open_file

mov al,0x21
call ackport
;call clrport64

iret
int21h_close_process:
mov [comm],al
mov si,process_returnstr
call prnstr
call colon
mov al,[comm]
call printh
pop eax
pop ax
pop ax

mov al,0x21
call ackport
;call clrport64

jmp kernel
int21h_open_file:
;pop ax
;mov [varbuff],ax
;inc [varbuff]
;pop ax
;pop ax

;mov ax,[varbuff]
;jmp ax

mov di,0x3500
mov byte [found],'i'

mov al,0x21
call ackport
;call clrport64

jmp fdir
iret

int4ah:
;mov cx,0xf000
;.emptyloop:
;cli
;nop
;dec cx
;loop .emptyloop
pusha

xor dx,dx
mov ds,dx
mov es,dx

mov ah,0x07
int 0x1a

call newlin_e
mov cx,0x0050
mov si,alarmtextstr
call prnstr
call newlin_e

mov si,dis
call prnstr
call colon
pop ax
call printwordh
call space

mov si,sis
call prnstr
call colon
pop ax
call printwordh
call space

mov si,bps
call prnstr
call colon
pop ax
call printwordh
call space

mov si,sps
call prnstr
call colon
pop ax
call printwordh
call space

mov si,bxs
call prnstr
call colon
pop ax
call printwordh
call space

mov si,dxs
call prnstr
call colon
pop ax
call printwordh
call space

mov si,cxs
call prnstr
call colon
pop ax
call printwordh
call space

mov si,axs
call prnstr
call colon
pop ax
call printwordh
call space

mov si,ips
call prnstr
call colon
pop ax
push ax
call printwordh
;call space

mov al,0x4a
call ackport
;call clrport64
call getkey
cmp ah,0x01
je .int4ah_break
iret
.int4ah_break:
pop ax
pop ax
pop ax
jmp kernel

int08h:
xor dx,dx
mov ds,dx
mov es,dx

mov ax,0x0e43
int 10h

mov al,0x08
call ackport
call clrport64

cmp [EnableDigitized],1                  ;If it's set to 1, process next lines of code
jne NoDigitizedSound                     ;If not, do the standard irq0 routine
   
   cmp al,0x80                                 ;If the byte taken from the memory is less than 80h,
                                                         ;turn off the speaker to prevent "unwanted" sounds,
   jb TurnOffBeeper                          ;like: ASCII strings (e.g. "WAVEfmt" signature etc).
   ;mov bx,[WAVSamplingRate]              ;Turn on the speaker with the WAV's sampling rate.
   mov bx,6000
   call Sound_On
   jmp Sound_Done
TurnOffBeeper:
   call Sound_Off
Sound_Done:
   inc esi                                         ;Increment ESI to load the next byte
NoDigitizedSound:   
iret

Sound_On:                                     ; A routine to make sounds with BX = frequency in Hz
   mov ax,0x34dd                        ; The sound lasts until NoSound is called
   mov dx,0x0012                
   cmp dx,bx                
   jnc Done1               
   div bx                
   mov bx,ax
   in al,0x61
   test al,3
   jnz A99                
   or al,3                                 ;Turn on the speaker itself
   out 0x61,al                
   mov al,0xb6
   out 0x43,al
A99:    
   mov al,bl 
   out 0x42,al              
   mov al,bh
   out 0x42,al
Done1:
   ret

Sound_Off:
   in al,0x61                 
   and al,11111100b                               ;Turn off the speaker
   out 0x61,al
   ret

PlayWAV:
   ;mov [WAVSamplingRate],10000;;;;;;;;;;;Your sampling rate;;;;;;;;;;;;
   ;mov [WAVFileSize],;;;;;;;;;;;; Size of your WAV file ;;;;;;;;;;;;;
   ;mov esi,FileLoaded ;;;;;;;;;;;;;; ESI = offset where the file is ;;;;;;;;;;;;;
   mov esi,0x3000
   ;mov cx,[WAVSamplingRate]                    ;IRQ0 fires e.g. 6000 times a second
   mov cx,6000
   call ProgramPIT                                  ;when a 6000Hz WAV file is played. This is how
                                                              ;the speaker can play the digitized sound:
                                                              ;it turns on and off very fast with the specified
                                                              ;wave sample rate.
   ;mov ecx,[WAVFileSize]                         ;Sets the loop point
   mov ecx,[size]
   mov [EnableDigitized],1                       ;Tells the irq0 handler to process the routines
Play_Repeat:
   lodsb                                              ;Loads a byte from ESI to AL
   hlt                                                 ;Wait for IRQ to fire
   loop Play_Repeat                              ;and the whole procedure is looped ECX times
   mov [EnableDigitized],0                     ;Tells the irq0 handler to disable the digitized functions
   mov cx,0x12                                 
   call ProgramPIT                                       ;Return to 18.2 kHz IRQ0
   call Sound_Off                                        ;Turn the speaker off just in case
   ret

set_timer:
mov al,0xb6
out 0x43,al
mov ax,1193
out 0x43,al
shr ax,8
out 0x43,al
ret

ProgramPIT:
mov al,0x36
out 0x43,al
mov ax,1193
;mov ax,1193180
;mov dx,1000
;div dx ;frequency
out 0x43,al
shr ax,8
out 0x43,al
ret

int09h:
in al,0x60
call printf

mov al,0x09
call ackport
call clrport64
iret

newprompt:
call getpos
xor dl,dl
call setpos
mov si,prompt
call prnstr
ret

alarm:
mov al,'H'
call printf
call colon
call gethex
mov ch,al
push cx
call colon
mov al,'M'
call printf
call colon
call gethex
pop cx
mov cl,al
push cx
call colon
mov al,'S'
call printf
call colon
call gethex
pop cx
mov dh,al
pusha
cmp byte [autostart],0xf0
jne .autostart_off
mov ah,0x08
int 0x1a
.autostart_off:
popa
mov ah,0x06
int 0x1a
jmp kernel

alarmtext:
mov di,alarmtextstr
call getstr
jmp kernel

c_setting_f:
mov si,c_size
call prnstr
call colon
mov bh,[size]
call printn
call space
mov si,c_head
call prnstr
call colon
mov bh,[head]
call printn
call space
mov si,c_track
call prnstr
call colon
mov bh,[track]
call printn

call newlin_e
mov al,'H'
call printf
call colon
mov al,[absoluteHead]
call printh
call space
mov al,'T'
call printf
call colon
mov al,[absoluteTrack]
call printh
call space
mov al,'S'
call printf
call colon
mov al,[absoluteSector]
call printh

call newlin_e
mov si,c_color
call prnstr
call colon
mov bh,[color]
call printn

call newlin_e
mov si,c_drive
call prnstr
call colon
mov bh,[drive]
call printn
call space
mov si,c_drive2
call prnstr
call colon
mov bh,[drive2]
call printn

call newlin_e
mov si,c_videomode
call prnstr
call colon
mov bh,[mode]
call printn

call newlin_e
mov si,c_difficulty
call prnstr
call colon
mov bh,[difficulty]
call printn

call space
mov si,c_length
call prnstr
call colon
mov bh,[length]
call printn

call newlin_e
mov si,c_scrolllen
call prnstr
call colon
mov bh,[scrolllength]
call printn

call newlin_e
mov si,c_loc
call prnstr
call colon
mov ax,[loc]
call printwordh

call space
mov si,c_loc2
call prnstr
call colon
mov ax,[loc2]
call printwordh

call space
mov si,c_loc3
call prnstr
call colon
mov ax,[loc3]
call printwordh

call newlin_e
mov si,c_page
call prnstr
call colon
mov ax,[page]
call printwordh

call newlin_e
mov si,c_fname
call prnstr
call colon
mov si,ImageName
call prnstr

call newlin_e
mov si,c_prompt
call prnstr
call colon
mov si,prompt
call prnstr

call newlin_e
mov si,c_alarmtext
call prnstr
call colon
mov si,alarmtextstr
call prnstr

call newlin_e
mov si,c_typemode
call prnstr
call colon
mov si,teletype
call switchshow

call space
mov si,c_scrollmode
call prnstr
call colon
mov si,scrollmode
call switchshow

call newlin_e
mov si,c_slowmode
call prnstr
call colon
mov si,slowmode
call switchshow

call space
mov si,c_score
call prnstr
call colon
mov si,score
call switchshow

jmp kernel

switchshow:
lodsb
cmp al,0xf0
je .switchon
cmp al,0x0f
je .switchoff
dec si
mov al,0x0f
mov [si],al
.switchoff:
mov si,coff
call prnstr
ret
.switchon:
mov si,con
call prnstr
ret

c_difficulty_f:
mov si,difficulty
call change
jmp kernel

signature:
db 'DivJ',0
jmp kernel

calc_options:
db '1.Add 2.Sub 3.Mul 4.Div 5.dtoh',0
drive_type_string:
db 'DriveType:',0
drive_number_string:
db 'Number of Drives:',0
drive_spt_string:
db 'Sectors per Track:',0
drive_head_string:
db 'Number of Heads:',0

EnableDigitized     db 0

bpbBytesPerSector:  	DW 512
bpbSectorsPerCluster: 	DB 1
bpbReservedSectors: 	DW 1
bpbNumberOfFATs: 	DB 2
bpbRootEntries: 	DW 224
bpbTotalSectors: 	DW 2880
bpbMedia: 		DB 0xf0  ;; 0xF1
bpbSectorsPerFAT: 	DW 9
bpbSectorsPerTrack: 	DW 18
bpbHeadsPerCylinder: 	DW 2
bpbHiddenSectors: 	DD 0
bpbTotalSectorsBig:     DD 0
bsDriveNumber: 	        DB 0x80

datasector  dw 0x0000
cluster     dw 0x0000
;msgProgress db ".", 0x00
absoluteSector db 0x05
absoluteHead   db 0x00
absoluteTrack  db 0x00

difficulty:
db 0x00
scrolllength:
db 0x01
length:
db 0x06
ball_x:
db 0x000C
ball_y:
db 0x000C
down_flag:
db 0xF0
right_flag:
db 0xF0
AI_flag:
db 0xF0
play_chance_flag:
db 0x00F0,0x0000
player_x:
db 0x000A
player_y:
db 0x000C
player2_x:
db 0x0000
player2_y:
db 0x0000

LBUTTON db 0x00 
RBUTTON db 0x00 
MBUTTON db 0x00 
XCOORD	db 0x00 
YCOORD	db 0x00 
XCOORDN db 0x00 
YCOORDN db 0x00 
XFLOW	db 0x00 
YFLOW	db 0x00 

deel	dw 0x0000
varbuff dw 0x0000
zerow	db 0x00
strlbt	db "Left button:   ", 0x00
strrbt	db "Right button:  ", 0x00
strmbt	db "Middle button: ", 0x00
strcdx	db "Mouse moved (X): ", 0x00
strcdy	db "Mouse moved (Y): ", 0x00
strneg	db "-", 0x00
strsp	db " ", 0x00
row	db 0x00
col	db 0x00

head:
db 0x00
track:
db 0x00

DRIVE_TYPE:
db 0x00
SECTORS_PER_TRACK:
db 0x0000
NUMBER_OF_DRIVES:
db 0x0000
NUMBER_OF_HEADS:
db 0x0000

teletype:
db 0x0f
scrollmode:
db 0xf0
slowmode:
db 0x0f
score:
db 0xf0
autostart:
db 0x0f
size:
db 0x01
drive:
db 0x80
drive2:
db 0x80
mode:
db 0x03
color:
db 0x31
color2:
db 0x18
xmouse:
dw 0x0000
ymouse:
dw 0x0000
page:
dw 0x0000
loc:
dw 0x3500
loc2:
dw 0x3000
loc3:
dw 0x4000
extra:
dw 0x0000
comm:
dw 0x0000,0x0000

c_load:
db 'load',0
c_save:
db 'save',0
c_run:
db 'run',0
c_text:
db 'text',0
c_code:
db 'code',0
c_doc:
db 'doc',0
c_print:
db 'print',0
c_clock:
db 'clock',0
c_drive:
db 'drive',0
c_drive2:
db 'drive2',0
c_debuginfo:
db 'debuginfo',0
c_loc:
db 'loc',0
c_loc2:
db 'loc2',0
c_loc3:
db 'loc3',0
c_htod:
db 'htod',0
c_reset:
db 'reset',0
c_cls:
db 'cls',0
c_prompt:
db 'prompt',0
c_color:
db 'color',0
c_typemode:
db 'typemode',0
c_videomode:
db 'videomode',0
c_scrolllen:
db 'scrolllen',0
c_difficulty:
db 'difficulty',0
c_length:
db 'length',0
c_scrollmode:
db 'scrollmode',0
c_slowmode:
db 'slowmode',0
c_memsize:
db 'memsize',0
c_settime:
db 'settime',0
c_setdate:
db 'setdate',0
c_alarm:
db 'alarm',0
c_alarmtext:
db 'alarmtext',0
c_autostart:
db 'autostart',0
c_setting:
db 'setting',0
c_install:
db 'install',0
c_score:
db 'score',0
c_icon:
db 'icon',0
c_point:
db 'point',0
c_page:
db 'page',0
c_track:
db 'track',0
c_head:
db 'head',0
c_size:
db 'size',0
c_fname:
db 'fname',0
c_sound:
db 'sound',0
c_reboot:
db 'reboot',0
c_restart:
db 'restart',0
c_play:
db 'play',0
c_calc:
db 'calc',0
c_paint:
db 'paint',0
c_star:
db 'star',0
c_cli:
db 'cli',0
c_hlt:
db 'hlt',0
c_fhlt:
db 'fhlt',0
c_jmp:
db 'jmp',0
axs:
db 'AX',0
cxs:
db 'CX',0
dxs:
db 'DX',0
bxs:
db 'BX',0
sps:
db 'SP',0
bps:
db 'BP',0
sis:
db 'SI',0
dis:
db 'DI',0
ips:
db 'IP',0
shutdownstr:
db 'System Halted. Safe to turn off.',0
process_returnstr:
db 'Process Return Value',0
drive_f:
db 'Drive Started:',0
imsgf:
db 'Floppy disk:',0
imsgh:
db 'Hard disk:',0
imsgo:
db 'Other:',0
imsgs:
db 'Installation Successful.',0
imsge:
db 'Failed',0
verstring:
db ' Clone OS (version 0.7)',0
command_list:
db 'THE Commands: load,save,run,text,code,doc,point,icon,paint,cls,reboot',0
extra_command_list:
db 'AndExtraCmds: loc,loc2,loc3,htod,reset,prompt,color,drive,drive2,restart',0
more_command_list:
db 'SomeMoreCmds: typemode,videomode,scrolllen,length,scrollmode,slowmode,memsize',0
assembly_code:
db 'OldeAssembly: cli,hlt,fhlt,jmp',0
common_control:
db 'Common Keys : Arrow,wasd,Tab- Change,E,(Esc or ~) - Close',0
extra_command:
db 'ExtraCommand: debuginfo,install,difficulty,score,play,calc',0
extra_command2:
db 'Extr2Command: sound,star,print,clock,head,track,page,size',0
file_command:
db 'FATFileComms: z-FDir,x-FSave,fname,a-cmpload,n-Fnew,q-quickload',0
interrupt_api:
db 'InterruptAPI: int 21h= 4c-close, 3d-fileopen int 4ah=alarm',0
time_list:
db 'Time setting: settime,setdate,alarm,alarmtext,autostart,setting',0
mint_list:
db 'Andthe Mints: d-date,t-time,c-clock,h-help,v-ver',0
mint2_list:
db 'Moreof Mints: m-mouse,s-space,p-pause,u-up,b-below,o-oh,l-line,e-exit',0
alarmtextstr:
db ' Alarm :Press {esc:jmp to kernel} or {other key to continue}.',0
con:
db 'ON',0
coff:
db 'OFF',0
ImageName:
db "COMMON  TXT",0,0
prompt:
db 'Bigger Picture:',0
found:
db 0x0000

times (512*18)-($-$$) db 0